﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL_HealthInsurance;
using DTO_HealthInsurance;
using System.Data;
using System.Data.SqlClient;
namespace HealthInsuranceMgm.Admin
{
    public partial class AddpolicyOnEMP : System.Web.UI.Page
    {
        DTOPoliciesOnEmployee objdto = new DTOPoliciesOnEmployee();
        DTOPolicyRequestDetail objpode = new DTOPolicyRequestDetail();
        BLLPolicyRequest objbllpode = new BLLPolicyRequest();
        BLLPolicyOnEmployee objbllPo = new BLLPolicyOnEmployee();
        BLLPolicies objpo = new BLLPolicies();
        DTOPolicies objpodo = new DTOPolicies();
        BLLCompany objcom = new BLLCompany();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                loadCompanyIdtoDDL();
                loadpolicytoDDl();
            }
        }

        public void loadpolicytoDDl() {
            ddlpolicyid.DataSource = objpo.ListPolicy();
            ddlpolicyid.DataTextField = "PolicyId";

            ddlpolicyid.DataValueField = "PolicyName";
            ddlpolicyid.DataBind();
        }

        public void loadCompanyIdtoDDL(){
            ddlcompanyId.DataSource = objcom.ListCompany();
            ddlcompanyId.DataTextField = "CompanyId";
            ddlcompanyId.DataValueField = "CompanyName";
            ddlcompanyId.DataBind();
        }
        public void message(string script)
        {

            Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", script, true);
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                string EmpNo = txtempid.Text;
                int PolicyId = Int32.Parse(ddlpolicyid.SelectedItem.ToString());
                string PolicyName = txtpolicyname.Text ;
                float policyAmount = float.Parse(txtpolicyamount.Text);
                float emi = float.Parse(txtpolicyemi.Text);
                float PolicyDuration = float.Parse(txtpolicyduration.Text);
                string PStartDate = txtpolicystartdate.Text;
                string PendDate = txtpolicyenddate.Text;
                string CompanyId = ddlcompanyId.SelectedValue.ToString();
                string CompanyName = txtcompanyname.Text;
                string Medical = txtmedicalid.Text;

                int comidRe =Int32.Parse( ddlcompanyId.SelectedItem.ToString());
                objpode.RequestDate = DateTime.Now.ToString();
                objpode.EmpNo = Int32.Parse(EmpNo);
                objpode.PolicyId = PolicyId;
                objpode.PolicyName = PolicyName;
                objpode.PolicyAmount = policyAmount;
                objpode.PolicyEmi = emi;
                objpode.CompanyId = comidRe;
                objpode.CompanyName = CompanyName;
                objpode.Status = "0";
                int j = objbllpode.insertPolicyRequset(objpode);

                objdto.EmpNo = EmpNo;
                objdto.PolicyId = PolicyId;
                objdto.PolicyName = PolicyName;
                objdto.PolicyAmount = policyAmount;
                objdto.Emi = emi;
                objdto.PolicyDuration = PolicyDuration;
                objdto.PolicyStartDate = PStartDate;
                objdto.PolicyEndDate = PendDate;
                objdto.CompanyId=CompanyId;
                objdto.CompanyName=CompanyName;
                objdto.Medical = Medical;

                int i = objbllPo.insertPolicyEmp(objdto);

                if (i > 0 && j>0)
                {

                    message("alert('Insert Succesfull');");

                }
            }
        }

        protected void ddlpolicyid_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtpolicyname.Text = ddlpolicyid.SelectedValue.ToString();
           
          
        }

        protected void ddlpolicyid_TextChanged(object sender, EventArgs e)
        {
          
           
        }

        protected void ddlcompanyId_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtcompanyname.Text = ddlcompanyId.SelectedValue.ToString();

        }

        protected void ddlcompanyId_TextChanged(object sender, EventArgs e)
        {

        }
    }
}